package cn.vehicle.controller;

import cn.vehicle.biz.CommonVehicleBiz;
import cn.vehicle.domains.vo.BasePage;
import cn.vehicle.domains.vo.Result;
import cn.vehicle.domains.vo.req.vehicle.AddCommonVehicleReq;
import cn.vehicle.domains.vo.req.vehicle.CommonVehicleListReq;
import cn.vehicle.domains.vo.req.vehicle.UpdateCommonVehicleReq;
import cn.vehicle.domains.vo.res.vehicle.CommonVehicleRes;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/common-vehicle") // 与其他接口路径规范一致，前缀为/api/common-vehicle
@Slf4j
@Tag(name = "CommonVehicleController", description = "普通车辆管理相关接口")
public class CommonVehicleController {

    @Resource
    private CommonVehicleBiz commonVehicleBiz;

    @PostMapping("/add")
    @Operation(description = "新增普通车辆接口")
    public Result<Void> addCommonVehicle(@RequestBody @Valid AddCommonVehicleReq req) {
        commonVehicleBiz.addCommonVehicle(req);
        return Result.success();
    }

    @PostMapping("/update")
    @Operation(description = "更新普通车辆接口")
    public Result<Void> updateCommonVehicle(@RequestBody @Valid UpdateCommonVehicleReq req) {
        commonVehicleBiz.updateCommonVehicle(req);
        return Result.success();
    }

    @PostMapping("/delete")
    @Operation(description = "删除单个普通车辆接口")
    public Result<Void> deleteCommonVehicle(
            @Parameter(schema = @Schema(name = "id", description = "车辆ID"))
            @RequestParam Long id) {
        commonVehicleBiz.deleteCommonVehicle(id);
        return Result.success();
    }

    @PostMapping("/get-by-id")
    @Operation(description = "查询普通车辆详情接口")
    public Result<CommonVehicleRes> getCommonVehicleById(
            @Parameter(schema = @Schema(name = "id", description = "车辆ID"))
            @RequestParam Long id) {
        return Result.success(commonVehicleBiz.getCommonVehicleById(id));
    }

    @PostMapping("/list")
    @Operation(description = "分页查询普通车辆列表接口")
    public Result<BasePage<CommonVehicleRes>> listCommonVehicles(@RequestBody @Valid CommonVehicleListReq req) {
        return Result.success(commonVehicleBiz.listCommonVehicles(req));
    }
}